package com.hddx.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

public class MyBatisUtils {
    public static  SqlSessionFactory build = null;
    static {
        String path = "mybatis-config.xml";
        //加载配置文件
        try {
            //alt+回车，按第一个
            Reader resoeures = Resources.getResourceAsReader(path);
            //创建SqlSessionFactory对象
            build = new SqlSessionFactoryBuilder().build(resoeures);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    public static SqlSession getSqlSession(){
        return build.openSession();
    } ;
}
